import router from './router'
import store from './store'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
NProgress.configure({ showSpinner: false })

const list = ['/login', '/404']
router.beforeEach((to, from, next) => {
  const token = store.state.user.token
  // token || list.includes(to.path) ? next() : next('/login')

  if (token) {
    NProgress.start()
    next()
  } else {
    if (list.includes(to.path)) {
      next()
    } else {
      next('/login')
      NProgress.done()
    }
  }
})

router.afterEach(() => {
  NProgress.done()
})
